/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proyecto.so1;

import java.net.*;
import java.io.*;
import javax.swing.JOptionPane;

/**
 *
 * @author antonio
 */
public class ReceiveMSG extends Thread implements Runnable{
    private boolean active;
    
    
    public ReceiveMSG(){
        active = true;
    }
    
    @Override
    public void run(){
        try{
            while(active){
                if(principal.receiveMSG){
                    Socket client = new Socket(principal.sender, 9999);
                    client.setReuseAddress(true);
                    System.out.println("Connected to " + client.getInetAddress() + " on port "
                    + client.getPort() + " from port " + client.getLocalPort() + " of "
                    + client.getLocalAddress());
                    InputStream input = client.getInputStream();
                    DataInputStream data = new DataInputStream(input);
                    JOptionPane.showMessageDialog(null, data.readUTF());
                    client.close();
                    principal.receiveMSG = false;
                }
            }
        }
        catch(Exception e){}
    }
    
}
